$(function(){
	showGoods_purchase(1);
});

function showGoods_purchase(pageIndex){
	$.ajax({
		url:"/selectGoods_purchases",
		type:"get",
		data:{
			pageIndex:pageIndex,
			name:$("#realName").val()
		},
		dataType:"json",
		success:function(data){
			var goods_purchases=data.beanList;
			var content="";
			var last="";
			content+="<thead>"
                    +"<tr>"
                    +"<th style='width: 150px;'>姓名</th>"
					+"<th>申购时间</th>"
					+"<th>申购物品</th>"
					+"<th>单价</th>"
					+"<th>申购数量</th>"
					+"<th>总价</th>"
					+"<th>审批状态</th>"
					+"<th style='width: 150px;'>操作</th>"
					+"</tr>"
					+"</thead>"
					+"<tbody>";
			for(var i=0;i<goods_purchases.length;i++){
				goods_purchase=goods_purchases[i];
				content+=" <tr class='success'>"
                        +"<td>"+goods_purchase.employee.name+"</td>"
                        +"<td>"+goods_purchase.gp_time+"</td>"
                        +"<td>"+goods_purchase.gp_name+"</td>"
                        +"<td>"+goods_purchase.gp_dprice+"</td>"
                        +"<td>"+goods_purchase.gp_number+"</td>"
                        +"<td>"+goods_purchase.gp_zprice+"</td>"
                        +"<td>"+goods_purchase.stay.s_name+"</td>"
                        +"<td>"
                        /*+"<a href='/selectGoods_claimByGc_id/"+goods_claim.gc_id+"'>修改</a>"*/
                        +"<a href='/selectGoods_purchase/"+goods_purchase.gp_id+"'><input type='button' class='btn btn-primary btn' value='修改' /></a>"
                        +"<button class='btn btn-primary btn' onclick='dodelete("+goods_purchase.gp_id+")'>删除</button>"
						+"</td>"
						+"</tr>"
			}
			content+="<tbody>";
			$(".table").html(content);
			if(data.pageIndex>6){
				last+='<a href="javascript:showGoods_purchase()">首页</a>'
			}
			if(data.pageIndex>1){
				last+='<a href="javascript:showGoods_purchase('+(data.pageIndex-1)+')">上一页 </a>';
			}
			for(var i = data.pageBegin; i <= data.pageEnd; i++){
				if(data.pageIndex==i){
					last+='['+i+']';
				}else if(data.pageIndex!=i){
					last+='<a href="javascript:showGoods_purchase('+i+')">['+i+']</a>';
				}
			}
			if(data.pageIndex<data.totalPage){
				last+='<a href="javascript:showGoods_purchase('+(data.pageIndex+1)+')">下一页 </a>';
			}
			if(data.pageIndex<(data.totalPage-4)){
				last+='<a href="javascript:showGoods_purchase('+data.totalPage+')">末页 </a><br />';
			}
			last+='<br /> 第'+data.pageIndex+'页，共'+data.totalPage+'页';
			
			$("#customers").html(last);
		},
		error:function(e){
			alert("error");
		}	
	})
}

function dodelete(gp_id){
	$.ajax({
		url:"/removeGoods_purchase",
		type:"post",
		data:{
			gp_id:gp_id
		},
		dataType:"text",
		success:function(data){
			alert(data);
			location.href="/officeSubscribe.html";
		},
		error:function(e){
			alert("error");
		}	
	})
}

/*function doupdate(gc_id){
	if(confirm("确认修改？")){
		window.location.href="<c:url value='/selectGoods_claimByGc_id/gc_id=' />"+gc_id;
	}
}*/

/*function doupdate(gc_id){
	$.ajax({
		url:"/selectGoods_claimByGc_id",
		type:"post",
		data:{
			gc_id:gc_id
		},
		dataType:"json",
		success:function(data){
			location.href="/update.html";
		}
	})
}*/